<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">申请激活</block>
		</cu-custom>
		<block v-if="shareimg">
			<view class="cu-form-group margin-top">
				请长按图片识别二维码，添加上级微信
			</view>
			<view class="text-center margin-top"  @tap="bc_code">
					<image :src="shareimg.my_qrcode" mode="aspectFill" style="z-index: 2; height: 300px; width: 300px;"></image>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">上级手机号码</view>
				<input placeholder="请输入昵称" name="input" v-model="shareimg.username" readonly="readonly" disabled="disabled" class="text-right"></input>
				<text class="hg-click" @click="paste(shareimg.username)"> 复制</text>
			</view>
			<!-- <view class="cu-form-group ">
				<view class="title">微信号</view>
				<input placeholder="请输入微信号" name="input" v-model="member.wx_member" class="text-right"></input>
			</view> -->
		
			<view class="margin-top-xl margin-lr padding-top-xl" v-if="shareimg ">
				<view class="cu-btn  lg round w100 light bg-blue"   v-if="submitLoading">
					<text class="cuIcon-loading2 cuIconfont-spin"></text> 提交中
				</view>
				<view v-else>
					<block v-if="sharemember">
						<view class="cu-btn w100 lg round bg-blue" v-if="sharemember.status==1">已激活</view>
						<view class="cu-btn w100 lg round bg-blue" v-if="sharemember.status==2" @tap="onSubmit">提交审批</view>
						<view class="cu-btn w100 lg round bg-blue" v-if="sharemember.status==0">激活中</view>
					</block>
					<block v-else>
					   <view class="cu-btn w100 lg round bg-blue" @tap="onSubmit">提交审批</view>	
					</block>
				</view>
				
			</view>
		</block>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				oid:0,
				shareimg:'',
				member:{},
				submitLoading:false,
				sharemember:'',
			}
		},
		onLoad(options) {
			if(options.id){
				this.oid=options.id
			}
			console.log(this.oid)
			this.$common.getConfig().then((config) => {
				this.config = config
				
			})
			this.$common.getMember().then((member) => {
				this.member = member
				this.showShare()
			})
			
		},
		
		methods: {
			showShare() {
				if (this.member.id > 0) {
					uni.showLoading({
						title: '加载中...',
					})
					this.$http.get('get_parent', {
						id: this.oid
					}).then((res) => {
						this.shareimg = res.data.data.member
						this.sharemember = res.data.data.m_rev
						this.submitLoading =false
						uni.hideLoading();
					})
				}
			},
			paste(value) {
				uni.setClipboardData({
					data: value
				});
				this.$common.showError('复制成功')
			},
			onSubmit() {
				
				if (this.submitLoading) return
				this.submitLoading = true
				// if (!this.member || !this.member.wx_member.trim()) {
				// 	this.$common.showError('请输入您的微信号')
				// 	this.submitLoading = false
				// 	return
				// }
				
				let formData = {
					uid: this.member.id,
					pid: this.shareimg.id,
					//wx_member: this.member.wx_member,
				}
				uni.showModal({
					title: "系统提示",
					content: "请确保添加上级微信，以免审批驳回",
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中...'
							})
							this.$http
								.post('review_update', formData)
								.then((response) => {
									var le=response.data.data;
									if(le.id>0){
										this.$common.showSuccess('申请成功', function() {
											setTimeout(function(){
												uni.navigateTo({
													// url:'/pages/shop/present_list'
													url:'/pages/member/index'
												})
											}, 750)
										})
									}
								})
								.catch((response) => {
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/member/index'
										})
									}, 750)
									
									uni.hideLoading()
								})
						}else{
							uni.hideLoading()
							this.submitLoading = false
						}
					}
				})	
			},
			bc_code(){
				
				// uni.showLoading({
				// 	title: '保存中...',
				// })
				let that = this;
				console.log('保存二维码', this.shareimg)
				uni.downloadFile({           //获得二维码的临时地址
					url:this.shareimg.wx_qrcode,
					success:(res)=>{
						//console.log('获取url',res)
						if(res.statusCode == 200){
							uni.saveImageToPhotosAlbum({
								filePath:res.tempFilePath,//传入临时地址
								success: () => {
									this.$common.showError('保存成功')//封装的提示
								},
								fail : () => {
									this.$common.showError('保存失败')
								}
							})
							uni.hideLoading()
						}
					}
				})
			},
		}
	}
</script>

<style>
	.c_button{
		position: fixed;
		bottom: 16%;
		margin: 0 auto;
		width: 50%;
		text-align: center;
		background: #36C7FF;
		color: #fff;
		border-radius: 20px;
		height: 34px;
		font-size: 14px;
		line-height: 34px;
		margin-left: 24%;
	}
	uni-image{
		width: 100%;
	}
	uni-input{
		height: 2.5em;
		width: 30%;
	}
	.hg-url{
		background: #ffffff;
		border-radius: 20px;
		padding-left: 20px;
	}
	.hg-click{
		width: 100rpx;
		height: 50rpx;
		font-size: 20rpx;
		background: #45AEFF;
		border-radius:20px;
		text-align: center;
		color: #ffffff;
		margin: 0 auto;
		padding-top: 10rpx;
	}
	
	.cu-rechange{
		position: fixed;
		bottom: 40px;
		left: 5%;
	}
</style>
